package com.example.test_demo.test;

import java.util.Scanner;
/**
 * @program: Demo
 * @description: 0-999输入的阿拉伯数字转换成英文
 * @author: yanghua
 * @create: 2020-12-08 11:52
 **/
public class EnglishNumberFormatter {
    public static void main(String[] args) {
        System.out.println(toEnglish(1));
    }
    private static final String[] bits = {"ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT,","NINE","TEN"};
    private static final String[] TEENS = {"ELEVEN", "TWELF","THIRTEEN","FOURTEEN","FIFTEEN","SIXTEEN","SEVETEEN","EIGHTEEN","NIGHTEEN"};
    private static final String[] TIES = {"TWENTY","THRITY","FORTY","FIFTY","SIXTY","SEVENTY","EIGHTY","NINETY"};
    private static Scanner sc;

    private static String toEnglish(int num) {
        if(num==0){
            return "Zero";
        }
        StringBuffer buffer = new StringBuffer();
        if(num >= 100) {
            buffer.append(pickHunder(num));
            if(num % 100 != 0) {
                buffer.append(" AND ");
            }
            num-=(num/100)*100;
        }
        boolean largerThan20 = false;
        if(num >= 20) {
            largerThan20 = true;
            buffer.append(pickTies(num));
            num -= (num / 10) * 10;
        }
        if(!largerThan20 && num > 10) {
            buffer.append(pickTeens(num));
            num = 0;
        }
        if(num > 0) {
            String bit = pickBits(num);
            if(largerThan20) {
                buffer.append(" ");
            }
            buffer.append(bit);
        }
        return buffer.toString();
    }

    private static String pickHunder(int num) {
        int hunder = num / 100;
        return bits[hunder - 1] + " HUNDER";
    }

    private static String pickTies(int num) {
        int ties = num / 10;
        return TIES[ties - 2];
    }

    private static String pickTeens(int num) {
        return TEENS[num - 11];
    }

    private static String pickBits(int num) {
        return bits[num - 1];
   }

}
